<?php

namespace app\datalog\sdk;

use app\datalog\ErrorLog;
use app\datalog\StorageDatalogBase;

class XyxSdkLog extends StorageDatalogBase
{
    // 数据存放位置
    protected $logPath = 'datalogs/xyxsdk';

    // 数据格式化方式
    protected $formatter = 'context';

    protected $maxSaveDay = 90;

    // 外部逻辑调用此接口进行日志落地
    public function addLog($data)
    {
        try {
            $this->addEventLog($data);
        } catch (\Throwable $exception) {
            ErrorLog::getInstance()->addThrowable($exception);
            return false;
        }

        return true;
    }

    public function addEventLog($params)
    {
        $params['#create_time'] = time();
        $params['#event_id']    = $params['event_id'];
        $params['#event_name']  = $params['event_name'];

        $this->log($params);
    }
}
